$(function() {

	var loginErrorBox = $('.login-error');
	var loginForm = $('form[name="login-form"]');
	var loginBtn = loginForm.find('input[name="login-btn"]');
	
	loginForm.submit(function() {
		$._post({
			url : $(this).attr('action'),
			data : $(this).serialize(),
			beforeSend : function() {
				setLangTypeCookie();
				loginBtn.attr('disabled', 'disabled');
				loginBtn.css('background-image', 'url(plug-in/login/images/load.gif)');
				loginBtn.css('background-color', 'rgb(74, 179, 198)');
				loginBtn.css('background-repeat', 'no-repeat');
				loginBtn.css('background-position', '10% 50%');
			},
			success : function(res) {
				if (res.status == '10000') {
					window.location.href = "forward.do?main";
				} else {
					loginErrorBox.show();
					$('#login-error-message').html(res.message);
					loginBtn.removeAttr('disabled', 'disabled');
					loginBtn.css('background-color', '');
					loginBtn.css('background-image', '');
					loginBtn.css('background-repeat', '');
					loginBtn.css('background-position', '');
				}
			}
		});
		return false;
	});
	
	loginErrorBox.find('img[name="login-error-btn"]').click(function() {
		loginErrorBox.hide();
	});
	
	var langTypeSelect = $('select[name="langType"]');
	var langType = $.cookie('langType');
	if (langType && langTypeSelect.val() != langType) {
		langTypeSelect.val(langType);
	}
	
	langTypeSelect.change(function() {
		$._post({
			url : 'login.do?alterLang',
			data : { 'langType' : $(this).val() },
			success : function(res) {
				if (res.status == '10000') {
					setLangTypeCookie();
				}
			}
		});
	});

});

try {
	if (window.top.location.href.indexOf('login.do') <= 0) {
		window.top.location.href = 'login.do';
	}
} catch (e) {
}

function setLangTypeCookie() {
	var langType = $('select[name="langType"]').val();
	$.cookie('langType', langType, { expires: 356, path: '/' });
}